package com.xcc.common.config;

import com.xcc.common.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

/**
 * @author frosty
 * @description
 * @date 2019-11-14 14:15:59
 */

//@Component
public class LoginMangement {


    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private RedisTemplate redisTemplate;


    @Bean
    public    RedisUtil redisUtil(){
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //如果不配置Serializer，那么存储的时候缺省使用String，如果用User类型存储，那么会提示错误User can't cast to String！
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        // 开启事务
        redisTemplate.setEnableTransactionSupport(true);
        if(redisUtil!=null){
            redisUtil.setRedisTemplate(redisTemplate);
            return  null;
        }
            RedisUtil redisUtil=new RedisUtil();
            redisUtil.setRedisTemplate(redisTemplate);
            return  redisUtil;
    }



}
